class Solution {
public:
    vector<int> countBits(int n)
    {
        vector<int> ret;
        for (int i=0; i<=n; i++)
        {
            int tmp=i;
            int num=0;
            while(tmp)
            {
                tmp&=tmp-1;
                num++;
            }
            ret.push_back(num);
        }
        return ret;
    }
};
